package com.rede.didiok.rank.web;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.rede.didiok.common.constant.conf.SysConf;
import com.rede.didiok.common.dto.rank.MemberCommentDto;
import com.rede.didiok.common.dto.rank.RankCountResultDto;
import com.rede.didiok.common.utils.ResultUtil;
import com.rede.didiok.rank.service.MemberCommentService;
import com.rede.didiok.rank.service.RankMemberService;
import com.rede.didiok.rank.service.RankService;

/**
 * @Author: Rede
 * @DateTime: 2023-08-31 20:05
 * @Description: 首页 RestApi
 */
@RestController
@RequestMapping("rank/feign/index")
public class IndexController {

    @Resource
    private RankMemberService rankMemberService;
    @Resource
    private RankService rankService;

    @Resource
    private MemberCommentService memberCommentService;

    /**
     * 获取总记录数
     *
     * @return
     */
    @GetMapping("/getTotalCount")
    String getTotalCount(){
        RankCountResultDto resultDto = new RankCountResultDto();
        // 榜单成员的数量
        Integer rankMemberCount = rankMemberService.getRankMemberCount();
        resultDto.setRankMemberCount(String.valueOf(rankMemberCount));

        // 评论的总数量
        MemberCommentDto memberCommentDto = new MemberCommentDto();
        Integer commentCount = memberCommentService.getCommentCount(memberCommentDto);
        resultDto.setMemberCommentCount(String.valueOf(commentCount));

        return ResultUtil.successWithData(resultDto);
    }

    @ApiOperation(value = "获取每个rank榜单下的榜单成员数目", notes = "获取每个rank榜单下的榜单成员数目", response = String.class)
    @RequestMapping(value = "/getRankMemberCountByRank", method = RequestMethod.GET)
    public String getRankMemberCountByRank() {
        List<Map<String, Object>> rankMemberCountByRank = rankMemberService.getRankMemberCountByRank();
        return ResultUtil.result(SysConf.SUCCESS, rankMemberCountByRank);
    }

    @ApiOperation(value = "获取每个榜单分类下的榜单数目", notes = "获取每个榜单类型下的榜单数目", response = String.class)
    @RequestMapping(value = "/getRankCountByCategory", method = RequestMethod.GET)
    public String getRankCountByCategory() {

        List<Map<String, Object>> blogCountByTag = rankService.getRankCountByCategory();
        return ResultUtil.result(SysConf.SUCCESS, blogCountByTag);
    }


    @ApiOperation(value = "获取一年内发布的榜单成员数", notes = "获取一年内发布的榜单成员数", response = String.class)
    @RequestMapping(value = "/getRankMemberContributeCount", method = RequestMethod.GET)
    public String getRankMemberContributeCount() {

        Map<String, Object> resultMap = rankMemberService.getRankMemberContributeCount();
        return ResultUtil.result(SysConf.SUCCESS, resultMap);
    }


}
